package com.jacobson.huobi.common.constants

object PeriodOffsetConstant {

    /** 60MIN 级别 */
    public val TYPE_MIN60 = 1
    /** H4 级别 */
    public val TYPE_H4 = 2
    /** H12 级别 */
    public val TYPE_H12 = 3
    /** day 级别 */
    public val TYPE_DAY = 4

    /** 60Min偏移 */
    private val OFFSET_MIN60 = 0
    /** 4h偏移 */
    private val OFFSET_H4 = 8
    /** 12h偏移 */
    private val OFFSET_H12 = 16
    /** day偏移 */
    private val OFFSET_DAY = 24


    /** 60Min偏移 */
    private val OFFSET_CHAIN_MIN60 = 0
    /** 4h偏移 */
    private val OFFSET_CHAIN_H4 = 16
    /** 12h偏移 */
    private val OFFSET_CHAIN_H12 = 32
    /** day偏移 */
    private val OFFSET_CHAIN_DAY = 48


    public fun comboSellLink4KLineNums(type: Int, value: Long): Long {
        return when(type) {
            TYPE_MIN60 -> value.shr(OFFSET_MIN60).and(0xFF)
            TYPE_H4 -> value.shr(OFFSET_H4).and(0xFF)
            TYPE_H12 -> value.shr(OFFSET_H12).and(0xFF)
            TYPE_DAY -> value.shr(OFFSET_DAY).and(0xFF)
            else ->0
        }
    }

    public fun comboLink4KLineStatus(type: Int, value: Long): Long {
        return when(type) {
            TYPE_MIN60 -> value.shr(OFFSET_MIN60).and(0xFF)
            TYPE_H4 -> value.shr(OFFSET_H4).and(0xFF)
            TYPE_H12 -> value.shr(OFFSET_H12).and(0xFF)
            TYPE_DAY -> value.shr(OFFSET_DAY).and(0xFF)
            else ->0
        }
    }

    public fun comboLink4KLineChains(type: Int, value: Long): Long {
        return when(type) {
            TYPE_MIN60 -> value.shr(OFFSET_CHAIN_MIN60).and(0xFFFF)
            TYPE_H4 -> value.shr(OFFSET_CHAIN_H4).and(0xFFFF)
            TYPE_H12 -> value.shr(OFFSET_CHAIN_H12).and(0xFFFF)
            TYPE_DAY -> value.shr(OFFSET_CHAIN_DAY).and(0xFFFF)
            else ->0
        }
    }

}